
/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path')
  , business = require('business/business');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.set("view options",{layout: false});
app.use(express.cookieParser());
app.use(express.session({secret: '1234567890QWERTY'}));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/index', routes.index);
app.get('/result', routes.result);
app.get('/about', routes.about);
app.get('/howitworks', routes.how_it_works);
app.post('/result', express.bodyParser(), function(req, res) {
	
	console.log('POST METHOD CALL');
	console.log('ImageURL: ' + req.body.image_url);
	console.log('INFO: ' + req.body.name+'+'+req.body.surname);
	//TODO: call business method and redirect to 
	//result page with analysis result in session
	var data = {};
	data.name = req.body.name;
	data.surname = req.body.surname;
	data.imageURL = req.body.image_url;
	business.linkBasedBust(data, 
		function(err, result, info) {
			console.log('Result:' + result);
			res.render('result', {
				'result':result
			});
			
		}
	);
	
	
	
});

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
